<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="/css/base.css">
    <link href="/css/purchase.2012.css?v=201410141639" rel="stylesheet" type="text/css">
    <title>我的购物车 - 淘淘商城</title>
    <script>
        var pageConfig  = {};
    </script>
<body>
<!--shortcut start-->
<jsp:include page="../commons/shortcut.jsp" />
<!--shortcut end-->
<div class="w w1 header clearfix">
    <div id="logo"><a href="http://www.taotaoo.xyz"><img clstag="clickcart|keycount|xincart|logo" src="/images/taotao-logo.gif" title="返回淘淘商城首页" alt="返回淘淘商城首页"></a></div>
    <div class="language"><a href="javascript:void(0);" onclick="toEnCart()"></a></div>
    <div class="progress clearfix">
        <ul class="progress-1">
            <li class="step-1"><b></b>1.我的购物车</li>
            <li class="step-2"><b></b>2.填写核对订单信息</li>
            <li class="step-3">3.成功提交订单</li>
        </ul>
    </div>
</div>
<div class="w cart">
    <div class="cart-hd group">
        <h2>我的购物车</h2>
 </span>
    </div>
    <div id="show">

        <div class="cart-frame">
            <div class="tl"></div>
            <div class="tr"></div>
        </div>
        <div class="cart-inner">
            <div class="cart-thead clearfix">
                <div class="column t-checkbox form">
                    <input data-cart="toggle-cb" name="toggle-checkboxes" id="toggle-checkboxes_up" type="checkbox" checked="checked" value="" onclick="check(this.checked)">
                    <label for="toggle-checkboxes_up">全选</label>
                </div>
                <div class="column t-goods">商品</div>
                <div class="column t-price">京东价</div>
                <div class="column t-promotion">优惠</div>
                <div class="column t-inventory">库存</div>
                <div class="column t-quantity">数量</div>
                <div class="column t-action">操作</div>
            </div>
            <div id="product-list" class="cart-tbody">
                <!-- ************************商品开始********************* -->
                <c:set var="totalPrice" value="0"></c:set>
                <c:forEach items="${cartList}" var="cart">
                    <c:set var="totalPrice"  value="${ totalPrice + (cart.itemPrice * cart.num)}"/>
                    <div id="product_11345721" data-bind="rowid:1" class="item item_selected ">
                        <div class="item_form clearfix">
                            <div class="cellp-checkbox"><input data-bind="cbid:1" class="checkbox" type="checkbox" name="toggle-checkboxes" checked="" value="${cart.itemId }"></div>
                            <div class="cell p-goods">
                                <div class="p-img">
                                    <a href="http://www.taotaoo.xyz/item/${cart.itemId }" target="_blank">
                                        <img clstag="clickcart|keycount|xincart|p-imglistcart" src="${cart.itemImage}" alt="${cart.itemTitle}" width="52" height="52">
                                    </a>


                                </div>
                                <div class="p-name">
                                    <a href="http://www.taotaoo.xyz/item/${cart.itemId }" clstag="clickcart|keycount|xincart|productnamelink" target="_blank">${cart.itemTitle}</a>
                                    <span class="promise411 promise411_11345721" id="promise411_11345721"></span>
                                </div>
                            </div>
                            <div class="cell p-price"><span class="price">￥<fmt:formatNumber groupingUsed="false" value="${cart.itemPrice / 100}" maxFractionDigits="2" minFractionDigits="2"/> </span></div>
                            <div class="cell p-promotion">
                            </div>
                            <div class="cell p-inventory stock-11345721">有货</div>
                            <div class="cell p-quantity" for-stock="for-stock-11345721">
                                <div class="quantity-form" data-bind="">
                                    <a href="javascript:void(0);" class="decrement" clstag="clickcart|keycount|xincart|diminish1" id="decrement">-</a>
                                    <input type="text" class="quantity-text" itemPrice="${cart.itemPrice}" itemId="${cart.itemId}" value="${cart.num }" id="changeQu" name="number">
                                    <a href="javascript:void(0);" class="increment" clstag="clickcart|keycount|xincart|add1" id="increment">+</a>
                                </div>
                            </div>
                            <div class="cell p-remove"><a id="remove-11345721-1" data-more="removed-87.20-1" class="cart-remove" href="javascript:del(${cart.id});">删除</a>
                            </div>
                        </div>
                    </div>
                </c:forEach>

            </div><!-- product-list结束 -->
            <div class="cart-toolbar clearfix">
                <div class="total fr">
                    <p><span class="totalSkuPrice">￥<fmt:formatNumber value="${totalPrice / 100}" maxFractionDigits="2" minFractionDigits="2" groupingUsed="true"/></span>总计：</p>
                    <p><span id="totalRePrice">- ￥0.00</span>优惠：</p>
                </div>
                <div class="amout fr"><span id="selectedCount"></span>件商品</div>
            </div>
            <div class="ui-ceilinglamp-1" style="width: 988px; height: 49px;"><div class="cart-dibu ui-ceilinglamp-current" style="width: 988px; height: 49px;">
                <div class="control fdibu fdibucurrent">
              <span class="column t-checkbox form">
                  <input data-cart="toggle-cb" name="toggle-checkboxes" id="toggle-checkboxes_down" type="checkbox" checked="" value="" class="jdcheckbox" onclick="check(this.checked)">
                  <label for="toggle-checkboxes_down">
                          全选
                  </label>
              </span>
                    <span class="delete">
                  <b>
                  </b>
                  <a href="javascript:delAllProduct();" id="remove-batch">
                          删除选中的商品
                  </a>
              </span>
                    <span class="shopping">
                  <b>
                  </b>
                  <a href="http://www.taotaoo.xyz" target="_blank" clstag="clickcart|keycount|xincart|coudanlink" id="continue">继续购物</a>
              </span>
                </div>
                <div class="cart-total-2014">
                    <div class="cart-button">
                  <span class="check-comm-btns" id="checkout-jd">
                      <a class="checkout" href="javascript:goToPay()" id="toSettlement" >去结算<b></b></a>
                  </span>
                        <span class="combine-btns" style="display:none">
                        <span class="fore1" style="display: none;">
                          <a href="" class="combine-btn">不支持合并付款</a>
                      </span>
                      <span class="fore2 hide" style="display: inline;">
                          <a href="javascript:goToOverseaOrder();" class="checkout-jdInt">去京东国际结算<b></b></a>
                          <a href="javascript:goToOrder();" class="checkout-jd">去京东结算<b></b></a>
                      </span>
                  </span>
                    </div>
                    <div class="total fr">
                        总计（不含运费）：
                        <span class="totalSkuPrice">￥<fmt:formatNumber value="${totalPrice / 100}" maxFractionDigits="2" minFractionDigits="2" groupingUsed="true"/></span>
                    </div>
                </div>
            </div></div>
        </div><!-- cart-inner结束 -->
    </div>
</div>
<!--推荐位html修改处-->


<script type="text/javascript" src="/js/base-v1.js"></script>
<!-- footer start -->
<jsp:include page="../commons/footer.jsp" />
<!-- footer end -->

<!-- 购物车相关业务 -->
<script type="text/javascript" src="/js/cart.js"></script>
<script type="text/javascript" src="/js/jquery.price_format.2.0.min.js"></script>
<script type="text/javascript">
    function check(checked)
    {
        //根据名字获取所有checkbox控件
        var allCheckBoxs=document.getElementsByName("toggle-checkboxes") ;
        var num;
        //循环设置控件为选中状态
        for (var i=0;i<allCheckBoxs.length ;i++) {
            if (allCheckBoxs[i].type == "checkbox") {
                allCheckBoxs[i].checked = checked;
            }
        }
    }

    //批量删除
    function delAllProduct(){
        var  flag = window.confirm("确定要删除吗？");
        var cks=document.getElementsByName("toggle-checkboxes");
        var str="";
        if(!flag){
            return;
        }
        //循环
        for(var i=1;i<cks.length-1;i++) {
            if (cks[i].checked) {
                str += cks[i].value+",";
            }
        }
        if(str=="" || str == null || str == 0){
           alert("请至少选中一个商品");
        }else {
            location.href = "/tbCart/delAllProduct?itemid=" + str;
            alert("删除成功");
        }
    }

    //删除
    function del(id) {
        var cartId = id;

        if(cartId>0){
            window.location.href="/tbCart/delCart?id="+cartId;
        }else{
            alert("删除失败");
        }
        alert("删除成功");

    }

    //加入订单
    function  goToPay() {
        var cks=document.getElementsByName("toggle-checkboxes");

        var str="";
        //循环
        for(var i=1;i<cks.length;i++) {
            if (cks[i].checked) {
                str += cks[i].value+",";
            }
        }
        if(str == null || str == "" ||str == ","){
            alert("您还没有添加商品~");
            return ;
        }else{
            window.location.href="/tbCart/Goorder?itemid="+str;
        }
    }

    //计算数量
    $(function () {
        $(document).ready(function () {
            var num1 = $(".quantity-text").val();
            var count =0;
            for (var i = 0;i<= num1.length;i++){
                var num = Number(num1);
                count+=num;
            }
            $("#selectedCount").text(count);
        })
    })

    //获取数量
    // $(function () {
    //       var Count =0;
    //       $("input[checked]").click(function () {
    //           var cks=document.getElementsByName("toggle-checkboxes");
    //           var num;
    //           //循环
    //           for(var i=1;i<cks.length;i++) {
    //               if (cks[i].checked) {
    //                   num = $("#changeQuantity").val();
    //                   var nums = Number(num);
    //                   Count += nums;
    //               }
    //           }
    //
    //
    //       })
    //   })

    //获取a标签
    // var btnList = document.getElementsByTagName("a");
    // for(var i = 0;i<btnList.length;i++){
    //     var aLink = btnList[i];
    //     var delnode = this.parentNode.parentNode;
    //     var pnode = delnode.parentNode;
    //     pnode.removeChild(delnode);
    // }



    // function bool() {
    //     var check = document.getElementsByTagName('input')[0];
    //     for(var i = 0;i< check.length;i++){
    //         console.log(check.checked);
    //     }
    //
    // }

    // function revCart(Num) {
    //     var sub = document.getElementById("remove-batch");
    //     var suds = sub.toggle-checkboxes;
    //
    //     for(var i = 0;i< suds.length;i++){
    //         if(Num < 0){
    //             suds[i].checked = !suds[i].checked;
    //         }else{
    //             suds[i].checked = Num
    //             alert(suds[i].checked);
    //         }
    //     }
    // }
</script>

</html>
